const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
// const { ModuleFederationPlugin } = require("webpack").container;
const { ModuleFederationPlugin } = require('@module-federation/enhanced/webpack');
const { VueLoaderPlugin } = require("vue-loader/dist/index");

module.exports = {
  mode: "development",
  entry: "./index.js",
  output: {
    path: path.resolve(__dirname, "./dist"),
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: "vue-loader",
      },

      {
        test: /\.js$/,
        loader: "babel-loader",
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "./index.html",
      title: "App3",
      filename: "index.html",
    }),
    new VueLoaderPlugin(),
    new ModuleFederationPlugin({
      name: "app3",
      filename: "app3.js",
      remotes: {
        app3: "app1@http://localhost:8888/button.js",
      },
      exposes: {
        "./App": "./App.vue",
        "./Button": "./Button.vue",
      },
      shared: { vue: { singleton: true } },
    }),
  ],
  devServer: {
    static: {
      directory: path.join(__dirname, "public"),
    },
    compress: true,
    port: 8080,
    host: "localhost",
  },
  resolve: {
    extensions: [".jsx", ".js"],
  },
  stats: "minimal",
};
